//
//  XBXJ_Manager.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/11/25.
//

/// ------
/// 来源：[Swift 单例模式 (Singleton)](https://www.jianshu.com/p/3081dac86c01)
/// ------

import Foundation

//!!!: 继承自`NSObject`的的单例

/// 1-1、最简单的单例
class XBXJ_Easy_NSObject_Manager: NSObject {
    static let shared = XBXJ_Easy_NSObject_Manager()
}

/// 1-2、真正的单例
class XBXJ_Real_NSObject_Manager: NSObject, NSCopying, NSMutableCopying {
    static let shared = XBXJ_Real_NSObject_Manager()
    
    private override init() { }

    override func copy() -> Any {
        return XBXJ_Real_NSObject_Manager.shared
//        return self
    }
    
    override func mutableCopy() -> Any {
        return self
    }
    
    func copy(with zone: NSZone? = nil) -> Any {
//        UIApplication
        return self
    }
    
    func mutableCopy(with zone: NSZone? = nil) -> Any {
        return self
    }
}


//!!!: 不继承自`NSObject`的的单例

/// 2-1、最简单的单例
class XBXJ_Manager21 {
    static let shared = XBXJ_Manager21()
}

/// 2-2、真正的单例
class XBXJ_Manager22 {
    static let shared = XBXJ_Manager22()
    
    private init() { }
}
